﻿<cfmodule template="../../tag/layout.cfm">
<form method="post" class="form">
  <fieldset>
    <legend>机构基本信息</legend>
    <table class="table" width="100%">
      <tbody>
        <tr>
          <th>编号</th>
          <td><input name="id" readonly /></td>
          <th>&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th>机构名称</th>
          <td><input name="text" class="easyui-validatebox" data-options="required:true" /></td>
          <th>机构编码</th>
          <td><input name="code"/></td>
        </tr>
        
        <tr>
          <th>机构地址</th> 
          <td colspan="3"><input name="address" class="easyui-validatebox" data-options="required:true"  style="width:435px;"/></td>
        </tr>
        
        <tr>
          <th>机构排序</th>
          <td><input name="seq" class="easyui-validatebox easyui-numberspinner"  data-options="min:0,max:100,required:true" value="0"  style="width:50px;" /></td>
          <th>上级机构</th>
          <td>
          	<select id="organizationid" name="organizationid">
          	</select>
          	<img class="iconImg ext-icon-cross" onclick="$('#organizationid').combotree('clear');" title="清空" />	
          </td>
        </tr>
      </tbody>
    </table>
  </fieldset>
</form>
</cfmodule>
<cfscript>
	if( structKeyExists(rc, "id")  && rc.id > 0 ){
		id = rc.id;
	}else{
		id = 0;
	}
</cfscript>
<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}
	
	var submitNow = function($dialog, $grid, $pjq) {
		var url;
		if ($(':input[name="id"]').val().length > 0) {
			url = '?action=organization.update'; //更新操作
		} else {
			url = '?action=organization.save';	//新增操作
		}

		$.post(url, fw.serializeObject($('form')), function(result) {
			if (result) {
				$grid.treegrid('reload');
				$dialog.dialog('destroy');
			}
		}, 'json');
	};
	
	var submitForm = function($dialog, $grid, $pjq) {
		if ($('form').form('validate')) {
			submitNow($dialog, $grid, $pjq);
		}
	};

	
	$(function(){
		//选择父Id
		var organizationid;
		organizationid = $('#organizationid').combotree({
				editable:false,
				idField:'id',
				textField:'text',
				parentField:'pid',
				url:'?action=organization.getTree'
		});
		
		//加载数据，初始进度条
		parent.$.messager.progress({
			text : '数据加载中....'
		});

		$.ajax({
		    type: "POST",
		    url: "?action=organization.get",
		    data: {
		        id:<cfoutput>#id#</cfoutput>
		    }
		}).done(function(result) {
			$('form').form('load', result); 
			parent.$.messager.progress('close');

		}, 'json');
	})
</script>	 
